# -*- coding: utf-8 -*-
"""
Module Description: 错误处理相关
Date: 2018/9/21
Author:Bai Jin Ping
"""
from common.tips_info import CodeDes
from framework.firefly_dc.global_errcode import GlobalErrCode


class GameException(Exception):
    """所有游戏异常的基类"""
    def __init__(self, stat, message="", extra=None):
        """
        :param message: 错误文本key(tips_info中定义的key)
        :param stat: 错误码errcode(errcode中定义的code)
        :param extra: 额外返回数据dict(尽量不用,仅当请求错误的场景下需要更丰富提示时才使用)
        """
        if not message:
            message = CodeDes.get(stat, "")
        super(Exception, self).__init__(message)
        self.stat = stat

        if extra is not None:
            assert isinstance(extra, dict)
        self.extra = extra

# class GameException(Exception):
#     """所有游戏异常的基类"""
#     def __init__(self, message, stat=GlobalErrCode.FAILED, extra=None):
#         """
#         :param message: 错误文本key(tips_info中定义的key)
#         :param stat: 错误码errcode(errcode中定义的code)
#         :param extra: 额外返回数据dict(尽量不用,仅当请求错误的场景下需要更丰富提示时才使用)
#         """
#         super(Exception, self).__init__(message)
#         self.stat = stat
#
#         if extra is not None:
#             assert isinstance(extra, dict)
#         self.extra = extra


class CrossGameException(GameException):
    """跨服游戏异常状态"""

    def __init__(self, message, stat=GlobalErrCode.FAILED, extra=None):
        super(CrossGameException, self).__init__(message, stat=stat)
        self.extra = extra

    def as_dict(self, info_dict):
        if self.extra:
            info_dict.update({'extra': self.extra})
        return info_dict


class CrossAdminGameException(GameException):
    """跨服后台异常的基类"""
